package educar.controllers;

import educar.gui.IView;
import educar.gui.LoginView;
import educar.models.Session;
import educar.models.User;

public class LoginController implements IController {
	private LoginView view;
        private PrincipalController principalController;
        private PrincipalDocenteController principalDocenteController;
        private PrincipalAlumnoController principalAlumnoController;
                                    
	public void process(String model){
		if(null!=view){
			if (User.authenticate(view.getUsername(), view.getPassword())){
				view.present("you are logged in as: " + Session.getCurrentUser().getUsername());
                                if ((Session.getCurrentUser().getRole().compareTo("Administrador")) == 0){
                                    principalController = new PrincipalController();
                                    principalController.setView(); 
                                }
                                if ((Session.getCurrentUser().getRole().compareTo("Docente")) == 0){
                                    principalDocenteController = new PrincipalDocenteController();
                                    principalDocenteController.setView();
                                }
                                if ((Session.getCurrentUser().getRole().compareTo("Alumno")) == 0){
                                    principalAlumnoController = new PrincipalAlumnoController();
                                    principalAlumnoController.setView();
                                }   
                                view.closeView();
			} else {
				view.present("Wrong username/password");
			}
                }
        }

	@Override
	public void setView(IView view) {
		this.view = (LoginView) view;	
	}	
}
